const BaseController = require("../core/baseController");
//轮播图的控制器
class CarouselController extends BaseController {
  async add() {
    const {
      ctx: {
        request: {
          body: { url }
        }
      },
      service
    } = this;
    let carousel = {
      url
    };
    try {
      await service.carousel.add(carousel);
      const result = await service.carousel.query();
      this.success(result);
    } catch (e) {
      this.failure("新增失败", e);
    }
  }

  async query() {
    try {
      const result = await this.service.carousel.query();
      this.success(result);
    } catch (e) {
      this.failure("查询失败", e);
    }
  }

  async delete() {
    const { ctx, service } = this;
    const _ids = ctx.request.body._ids;
    try {
       await service.carousel.delete(_ids);
      const result = await service.carousel.query();
      this.success(result);
    } catch (e) {
      this.failure("删除失败", e);
    }
  }
}

module.exports = CarouselController;
